package com.ysd.lis.controller.sys;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.ysd.common.Result;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.request.SysParamDto;
import com.ysd.lis.request.SysParamParam;
import com.ysd.lis.service.SysParamValueService;
import com.ysd.util.ToolsUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author prs
 * @since 2024-2-21
 */
@Api(tags = "系统参数值")
@RestController
@RequestMapping("/api/sys/sysParamValue")
public class SysParamValueController extends BaseController {

    @Autowired
    SysParamValueService sysParamValueService;

    @ApiOperation("根据paramCode查询出参数及参数下的分组和字段属性")
    @GetMapping("/findSysParamInfoByCode")
    public Result findSysParamInfoByCode(SysParamParam param) throws JsonProcessingException {
        return sysParamValueService.findSysParamInfoByCode(param);
    }

    @ApiOperation("保存扩展属性值")
    @PostMapping("/saveSysParamValueList")
    @LogDetail(requestParam = "saveSysParamValueList", operationType = OperationType.INSERT, module = "批量更新系统参数值", content = "通过系统参数模块，增加参数值", businessName = "name")
    public Result saveSysParamValueList(@RequestBody SysParamDto dto) throws JsonProcessingException {
        Result r = sysParamValueService.saveSysParamValueList(dto);
        if (ToolsUtils.isNotEmpty(r.getStatus().get("code")) && ("1".equals(r.getStatus().get("code"))||1==(Integer)r.getStatus().get("code"))) {
            sysParamValueService.refreshRedis(dto.getOrgId());
        }
        return r;
    }

    @ApiOperation("根据paramCode查询出参数及参数下的分组和字段属性值")
    @GetMapping("/findSysParamInfoValueList")
    public Result findSysParamInfoValueList(SysParamParam param) throws JsonProcessingException {
        return sysParamValueService.findSysParamInfoValueList(param);
    }

    @ApiOperation("根据paramCode查询出参数及参数下的分组和字段属性以及数据值")
    @GetMapping("/findSysParamFieldAndValueByCode")
    public Result findSysParamFieldAndValueByCode(SysParamParam param) throws JsonProcessingException {
        return sysParamValueService.findSysParamFieldAndValueByCode(param);
    }
}
